package sdf;

//////////////////////////////////////////////////////////////////////////
//// PortSampleRate
/**

@author Ivan Jeukens
@version v 0.1 27/06/2003
*/
public class PortSampleRate  {

    public PortSampleRate(String name) {
        _name = name;

        init = new MinMax();
        consumption = new MinMax();
        production = new MinMax();
    }

    ///////////////////////////////////////////////////////////////////
    ////                      public variables                     ////
    
    public MinMax init;
    public MinMax production;
    public MinMax consumption;

    ///////////////////////////////////////////////////////////////////
    ////                        public methods                     ////

    public String getName() {
        return _name;
    }
    
    public void setChannelSize(int size) {
        init.setChannelSize(size);
        consumption.setChannelSize(size);
        production.setChannelSize(size);
    }
    
    public void reset() {
        init.reset();
        consumption.reset();
        production.reset();
    }
    
    public Object clone() {
        PortSampleRate clone = new PortSampleRate(_name);

        clone.init = (MinMax) init.clone();
        clone.production = (MinMax) production.clone();
        clone.consumption = (MinMax) consumption.clone();

        return clone;
    }

    public boolean isConsumptionHomogeneous() {
        if(!consumption.isHomogeneous()) return false;
        return true;
    }

    public boolean isProductionHomogeneous() {
        if(!production.isHomogeneous()) return false;
        return true;
    }

    public void updateInit(PortSampleRate ps) {
        init.update(ps.init);
    }

    public void updateProduction(PortSampleRate ps) {
        production.update(ps.production);
    }

    public void updateConsumption(PortSampleRate ps) {
        consumption.update(ps.consumption);
    }

    public String toString() {
        StringBuffer buf = new StringBuffer();

        buf.append("Sample rates for port " + _name + "\n");
        buf.append("Initialization: ");
        buf.append(init.toString());

        buf.append("Consumption: ");
        buf.append(consumption.toString());

        buf.append("Production: ");
        buf.append(production.toString());

        return buf.toString();
    }

    ///////////////////////////////////////////////////////////////////
    ////                        private methods                    ////

    ///////////////////////////////////////////////////////////////////
    ////                        private variables                  ////

    private String _name;
}
